package jnpf.database.datatype.limit;

import jnpf.database.datatype.limit.base.DtLimitBase;
import jnpf.database.datatype.limit.base.DtLimitModel;
import jnpf.database.datatype.limit.util.DtLimitUtil;
import jnpf.database.datatype.model.DataTypeModel;
import jnpf.database.datatype.model.ViewDtModel;

/**
 * 类功能
 *
 * @author JNPF开发平台组 YanYu
 * @version V3.3
 * @copyright 引迈信息技术有限公司
 * @date 2022-06-06
 */
public class FloatLimit extends DtLimitBase {

    public final static String CATEGORY = "type-Float";
    public final static String JAVA_TYPE = "float";

    public FloatLimit(Boolean modifyFlag, Integer defaultPrecision, Integer maxPrecision, Integer maxScale){
        instanceCommon(modifyFlag, defaultPrecision, maxPrecision, maxScale, null);
    }

    public FloatLimit(){
        instanceCommon(false, null, null, null, null);
    }

    public FloatLimit(Integer fixedPrecision){
        instanceCommon(false, null, null, null, fixedPrecision);
    }

    public FloatLimit(Integer maxPrecision, Integer maxScale){
        instanceCommon(false, null, maxPrecision, maxScale, null);
    }

    public void instanceCommon(Boolean isModifyFlag, Integer defaultPrecision, Integer maxPrecision, Integer maxScale, Integer fixedPrecision){
        init(CATEGORY);
        this.isModifyFlag = isModifyFlag;
        // 精度
        DtLimitModel numPrecisionModel = new DtLimitModel();
        numPrecisionModel.setDefaults(defaultPrecision);
        numPrecisionModel.setMax(maxPrecision);
        numPrecisionModel.setFixed(fixedPrecision);
        this.numPrecisionLm = numPrecisionModel;
        // 标度
        DtLimitModel numScaleModel = new DtLimitModel();
        numScaleModel.setMax(maxScale);
        numScaleModel.setMin(0);
        this.numScaleLm = numScaleModel;
    }

    @Override
    public DataTypeModel convert(ViewDtModel viewDtModel){
        DataTypeModel dataTypeModel = DtLimitUtil.convertNumeric(viewDtModel);
        dataTypeModel.setJavaType(JAVA_TYPE);
        if(this.isModifyFlag){
            DtLimitUtil.getNumericLength(dataTypeModel);
        }
        return dataTypeModel;
    }

}
